import * as apis from '../services/seekTechnologyService.js'

export default {
    namespace:'seekTechnology',

    state:{
        seekTechnologyList:[]
    },

    reducers:{
        setSeekTechnologyList:setSeekTechnologyList
    },

    effects:{
        getSeekTechnologyTableData:getSeekTechnologyTableData,
        createTechnologySeek:createTechnologySeek,
        deleteTechnologySeek:deleteTechnologySeek
    }
}

function setSeekTechnologyList(state,payload){
    let _state = JSON.parse(JSON.stringify(state));
    _state.seekTechnologyList = payload.data;
    return _state
}

/**
 * 查询技术征求信息列表
 */
function* getSeekTechnologyTableData(payload,{select,call,put}){
    let result = yield call(apis.getSeekTechnologyTableData)
    for(let i = 0;i<result.data.data.length;i++){
        for(let key in result.data.data[i]){
            if(key == "functionalMaterials"){
                if(result.data.data[i][key] == "1"){
                    result.data.data[i][key] = "生活垃圾"
                }
                if(result.data.data[i][key] == "2"){
                    result.data.data[i][key] = "农业废物"
                }
                if(result.data.data[i][key] == "3"){
                    result.data.data[i][key] = "工业固体废物"
                }
                if(result.data.data[i][key] == "4"){
                    result.data.data[i][key] = "危险废弃物"
                }
                if(result.data.data[i][key] == "5"){
                    result.data.data[i][key] = "其他"
                }
            }
    
            if(key == "technologyCategory"){
                if(result.data.data[i][key] == "1"){
                    result.data.data[i][key] = "固废分离技术"
                }
                if(result.data.data[i][key] == "2"){
                    result.data.data[i][key] = "循环再利用技术"
                }
                if(result.data.data[i][key] == "3"){
                    result.data.data[i][key] = "减少污染"
                }
                if(result.data.data[i][key] == "4"){
                    result.data.data[i][key] = "分类回收"
                }
                if(result.data.data[i][key] == "5"){
                    result.data.data[i][key] = "其他"
                }
            }
        }
    }

    yield put({
        type:"seekTechnology/setSeekTechnologyList",
        data:result.data.data
    })
}

/**
 * 创建技术征求信息
 */
function* createTechnologySeek(payload,{select,call,put}){
    let result = yield call(apis.createTechnologySeek,payload.data)

    yield put({
        type:"app/setServerRes",
        data:result.data
    })
}

/**
 * 删除技术征求信息
 */
function* deleteTechnologySeek(payload,{select,call,put}){
    let result = yield call(apis.deleteTechnologySeek,payload.data)

    yield put({
        type:"app/setServerRes",
        data:result.data
    })
}
